package com.yyw.gulimall.cart.vo;

import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Classname CartVo
 * @Description 购物车Vo类
 * @Date 2020/12/21 14:47
 * @Created yyw
 */
public class CartVo {
    List<CartItemVo> items = new ArrayList<>(); //购物车子项信息

    private Integer countNum;  //商品数量

    private Integer countType; //商品类型数量

    private BigDecimal totalAmount; //商品总价

    private BigDecimal reduce = new BigDecimal("0.00"); //减免价格


    public List<CartItemVo> getItems() {
        return items;
    }

    public void setItems(List<CartItemVo> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        Integer count = 0;
        if (!CollectionUtils.isEmpty(this.items)) {
            for (CartItemVo item : items) {
                Integer i = item.getCount();
                count += i;
            }
        }
        return count;
    }

    public void setCountNum(Integer countNum) {
        this.countNum = countNum;
    }

    public Integer getCountType() {
        if (!CollectionUtils.isEmpty(this.items)) {
            return this.items.size();
        }
        return countType;
    }

    public void setCountType(Integer countType) {
        this.countType = countType;
    }

    public BigDecimal getTotalAmount() {
        if (!CollectionUtils.isEmpty(this.items)) {
            BigDecimal total = new BigDecimal("0");
            for (CartItemVo item : this.items) {
                if (item.isCheck()) {
                    total = total.add(item.getTotalPrice());
                }
            }
            return total;
        }
        return totalAmount;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
